/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package shaman.storage.impl.util;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.util.Iterator;
import shaman.storage.impl.file.IterationException;

/**
 *
 * @author dmitriy
 */
public class ObjectStreamMultiIterable<T> {

    public final ObjectInputStreamSource src;
    public final Class<? extends T> ocl;

    public ObjectStreamMultiIterable(ObjectInputStreamSource src, Class<? extends T> ocl) {
        this.src = src;
        this.ocl = ocl;
    }

    public Iterator<T> iterator() throws IterationException {
        ObjectInputStream ois;
        try {
            ois=src.getInputStream();
        } catch (IOException ex) {
            throw new IterationException("Unable to start enumeration", ex);
        }
        return new ObjectStreamIterator<T>(ois, ocl);
    }

}
